#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_testdcb.h"
#include <thread>

#include "SerialPort/SerialPort.h"

namespace BS = Base::Comm;

class testdcb : public QMainWindow
{
    Q_OBJECT
signals:
    void signal_receive_data(const QString&msg);
private slots:
    void OnOpen();
    void OnClose();
    void OnQuery();
    void OnAutoSend(bool );
    void on_pushButton_clear_clicked();
    void WriteReceiveMsg(const QString& msg);
public:
    testdcb(QWidget *parent = nullptr);
    ~testdcb();
protected:
    void OnInitDialog();
private:
    void InitSerial();
    void UnInitSerial();
    void InitUI();
    void WriteMsg(unsigned char *buf,int size);
    void WriteMsg(const QString& msg);
    void WriteData(unsigned char* buf, int size=8);
    void OnCicleQuery();
private:
    Ui::testdcbClass ui;
    BS::SerialPort* m_serial;
    std::thread m_thread;
    std::jthread m_query_thread;
};
